﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 字符串不能匹配任意给定的字符串, 示例:
/// <code>
/// [VNotMatchRegexAny(["127\\.0\\.0\\.1", "^10\\.", "^192\\.168\\.", "^172\\.1[6-9]\\.", "172\\.2[0-9]\\.", "172\\.3[01]\\."], errorMessage: "必须是正确的公网IP")]
/// public string IP { get; set; }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class VNotMatchRegexAnyAttribute(string[] patterns, string errorMessage = null) : Attribute, IValidateAction
{
    public string[] Patterns { get; set; } = patterns;
    public string ErrorMessage { get; set; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateStringExtensions.MustNotMatchRegexAnyInternal(ctx, ctx.ModelValue?.ToString(), Patterns, ErrorMessage);
    }
}
